<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>company</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
  <link rel="stylesheet" href="../css/public.css" media="all">
</head>

<body class="class1">
<div id="refreshs">
  <div class="layuimini-container">
    <div class="layuimini-main">
      <script type="text/html" id="toolbarDemo">
      </script>
      <form class="layui-form" action="">
        <div class="layui-row">
          <div class="layui-col-md3">
            <div class="layui-form-item">
              <label class="layui-form-label">项目编号：</label>
              <div class="layui-input-block">
                <input type="text" name="proNum" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
              </div>
            </div>
          </div>
          <div class="layui-col-md3">
            <div class="layui-form-item">
              <label class="layui-form-label">企业名称：</label>
              <div class="layui-input-block">
                <input type="text" name="enterpriseName" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
              </div>
            </div>
          </div>
          <div class="layui-col-md3">
            <div class="layui-form-item">
              <label class="layui-form-label">项目名称：</label>
              <div class="layui-input-block">
                <input type="text" name="proName" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
              </div>
            </div>
          </div>
          <div class="layui-col-md3">
            <div class="layui-form-item">
              <label class="layui-form-label">录入时间：</label>
              <div class="layui-input-inline">
                <input type="text" name="createTime" id="date" placeholder="请选择日期" autocomplete="off" class="layui-input">
              </div>
            </div>
          </div>
        </div>
        <div class="layui-row">
          <div class="layui-col-md3">
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" type="button" lay-submit lay-filter="search">查询</button>
                <button class="layui-btn layui-btn-primary" lay-submit lay-filter="reset">重置</button>

                <!-- <button type="reset" id="reset" class="layui-btn layui-btn-primary">重置3</button> -->
              </div>
            </div>
          </div>
          <button class="layui-btn" type="button" lay-submit lay-filter="add" id="add">添加</button>
          <button type="button" class="layui-btn layui-btn-primary" id="upload">
            <i class="layui-icon">&#xe67c;</i>导入
          </button>
        </div>
      </form>
      <table class="layui-hide" id="CompanyTableId" lay-filter="currentTableFilter"></table>
      <script type="text/html" id="currentTableBar">
        <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-handle" lay-event="handle">查看</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
      </script>

    </div>
  </div>
</div>
  <script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
  <script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
  <script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
  <script src="../js/ManualPaging.js"></script>
  <script>
    if (!localStorage.getItem("userName")) {
      window.location = './login-1.html';
    }
    layui.use(['form', 'table', 'laydate', 'upload', 'miniTab'], function() {
      var $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        laydate = layui.laydate,
        upload = layui.upload,
        miniTab = layui.miniTab

      laydate.render({
        elem: '#date' //指定元素
      });


      //所有元素
      var demolist;
      // 文件上传
      var uploadInst = upload.render({
        elem: '#upload', //绑定元素  
        url: '/pro/uploadPro/', //上传接口
        before:function(b){

          $.ajax({
            url: publicurl + 'pro/checkUser',
            type: "GET",
            dataType: 'json',
            async: false,
            success: function (r) {

              if (r.status == 1) {
                layer.alert(r.msg + '<br>' + r.obj, {
                  icon: 2,
                  title: "提示"
                }, function (index) {
                  if (r.obj == '未登录') {
                    location.href = 'login-1.html'
                  }else{
                    layer.close(index);
                  }

                });
              }else{
              }
            }
          });
          return;
        },   
        done: function(res) {
          if (res.status == 1) {
            layer.alert(res.msg + '<br>' + res.obj, {
              icon: 2,
              title: "提示"
            }, function (index) {
              if (res.obj == '未登录') {
                location.href = 'login-1.html'
              }else{
                layer.close(index);
              }

            });
          }else{
            layer.open({
              content: '上传成功',
              time: 1000
            });
            setTimeout(() => {
              window.location.reload()
            }, 1000)
          }
        },
        error: function() {
          //请求异常回调
          layer.open({
            content: '上传失败',
            time: 1000
          });
          setTimeout(() => {
            window.location.reload()
          }, 1000)
        },
        accept: 'file'
      });

      // 表格
      var insTb = table.render({
        elem: '#CompanyTableId',
        toolbar: '#toolbarDemo',
        defaultToolbar: [''],
        url: '' + publicurl + 'pro/getPros',
        request: {
          pageName: 'pageNum', //页码的参数名称，默认：page
          limitName: 'pageSize' //每页数据量的参数名，默认：limit
        },
        parseData: function(res) { //res 即为原始返回的数据
          //处理时间
          // console.log(res)
          // for (var i = 0; i < res.obj.length; i++) {
          //   for (k in res.obj[i]) {
          //     res.obj[i]["createdDate"] = renderTime(res.obj[i].createdDate);
          //     res.obj[i]['status'] = judgeState(res.obj[i].status)
          //   }
          // }
          demolist=res.obj.list
          console.log(demolist)
//console.log(res.obj.list)
          return {
            "code": res.status, //解析接口状态,默认成功是0
            "msg": res.msg, //解析提示文本
            "count": res.obj.total, //解析数据长度
            "data": res.obj.list //解析数据列表
          };
        },
        cols: [
          [
            // { type: "checkbox", width: '5%', align: "center" },
            // {field: 'id', width:'13%', title: 'ID',align:"center"},
            { field: 'proNum', width: '10%', title: '项目编号', align: "center" },
            { field: 'enterpriseName', width: '22%', title: '企业（单位）名称', align: "center" },
            { field: 'area', width: '12%', title: '所属区、县（市）', align: "center" },
            { field: 'proName', width: '12%', title: '项目名称', align: "center" },
            { field: 'contractAmount', width: '8%', title: '合同额（万元）', align: "center" },
            { field: 'concacts', title: '联系人', width: '8%', align: "center" },
            { field: 'createTime', title: '录入时间', width: '12%', align: "center" },
            { title: '操作', width: '16%', toolbar: '#currentTableBar', align: "center" }
          ]
        ],
        limits: [10, 15, 20, 25, 50, 100],
        limit: 10,
        id: 'tabel',
        page: true,
        skin: 'line',
        done: function(res, curr, count) {
          // if (res.code == 1) {
          //   layer.alert(res.msg + '<br>' + res.data, {
          //     icon: 2,
          //     title: "提示"
          //   });
          // }

          // if (count > 0) {
          //   goPage(1);
          // }
        }
      });
      /**
       * toolbar监听事件
       */
      // table.on('toolbar(currentTableFilter)', function (obj) {
      //   if (obj.event === 'add') {  // 监听添加操作
      //     var index = layer.open({
      //       title: '添加用户',
      //       type: 2,
      //       shade: 0.2,
      //       maxmin:true,
      //       shadeClose: true,
      //       area: ['100%', '100%'],
      //       content: '../page/table/add.html',
      //     });
      //     $(window).on("resize", function () {
      //       layer.full(index);
      //     });
      //   } else if (obj.event === 'delete') {  // 监听删除操作
      //     var checkStatus = table.checkStatus('currentTableId')
      //             , data = checkStatus.data;
      //     layer.alert(JSON.stringify(data));
      //   }
      // });



      form.on('submit(search)', function(data) {
        table.reload('tabel', {
          url: '' + publicurl + 'pro/getPros',
          page: { curr: 1 },
          where: data.field // 查询条件
        }, 'data')
      });
      form.on('submit(reset)', function(data) {
        table.reload('tabel', {
          url: '' + publicurl + 'pro/getPros',
          page: { curr: 1 }
        }, 'data')
      });
      // $("#reset").click(function(data) {
      //   console.log('===========')
      //   console.log(data.field)
      //   console.log('===========')

      //   table.reload('tabel', {
      //     url: '' + publicurl + 'pro/getPros',
      //     page: { curr: 1 },
      //     where: {
      //       pageNum: 1,
      //       pageSize: 10
      //     }
      //   }, 'data')
      // });

      // form.on('reset(rset)', function(data) {
      //   table.reload('tabel', {
      //     url: '' + publicurl + 'pro/getPros',
      //     page: { curr: 1 },
      //     where: data.field // 查询条件
      //   }, 'data')
      // });

      // function renderTime(date) {
      //   var dateee = new Date(date).toJSON();
      //   return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
      // }

      // function judgeState(state) {
      //   var stateText = '';
      //   if (state == 'ASSIGNED') {
      //     stateText = '执行中';
      //   } else {
      //     stateText = state
      //   }
      //   return stateText
      // }

      //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

      //点击编辑跳窗口
      //删除功能需要接口
      // table.on('tool(currentTableFilter)', function (obj) {
      //   var data = obj.data;
      //   if (obj.event === 'edit') {
      //
      //     var index = layer.open({
      //       title: '编辑用户',
      //       type: 2,
      //       shade: 0.2,
      //       maxmin:true,
      //       shadeClose: true,
      //       area: ['100%', '100%'],
      //       content: '../page/table/edit.html',
      //     //  content: '../page/company-detail.html',
      //     });
      //     $(window).on("resize", function () {
      //       layer.full(index);
      //     });
      //     return false;
      //   } else if (obj.event === 'delete') {
      //     layer.confirm('真的删除行么', function (index) {
      //       obj.del();
      //       layer.close(index);
      //     });
      //   }
      // });
/*

     //添加按钮
     //
      table.on('toolbar(currentTableFilter)', function (obj) {
        if (obj.event === 'add') {  // 监听添加操作
          var index = layer.open({
            // title: '添加用户',
            // type: 2,
            // shade: 0.2,
            // maxmin:true,
            // shadeClose: true,
            // area: ['100%', '100%'],
            //  //content: '../page/table/adds.html',
            // content: '../page/company-detail.html',

          });
          // $(window).on("resize", function () {
          //   layer.full(index);
          // });
          miniTab.openNewTabByIframe({
            href: "page/company-detail.html" ,
            title: "企业详情",
          });
        // } else if (obj.event === 'delete') {  // 监听删除操作
          //   var checkStatus = table.checkStatus('currentTableId')
          //           , data = checkStatus.data;
          //   layer.alert(JSON.stringify(data));
        }
       });
*/

//监听表格操作
      table.on('tool(currentTableFilter)', function(obj) {
        if (obj.event === 'handle') { // 监听查看操作
          // 打开新的窗口
          miniTab.openNewTabByIframe({
            href: "page/company-detail.html?id=" + obj.data.id+"&type="+"4",
            title: "企业详情",
          });
        }else if(obj.event === 'edit') {
          $.ajax({
            url:publicurl + 'pro/checkUser',
            type:"GET",
            dataType: 'json',
            async:false,
            success: function(res) {
              if (res.status == 1) {
                layer.alert(res.msg + '<br>' + res.obj, {
                  icon: 2,
                  title: "提示"
                }, function (index) {
                  if(res.obj=='未登录'){
                    location.href = 'login-1.html'
                  }else{
                    layer.close(index);
                  }

                });
              }else{
                  miniTab.openNewTabByIframe({
                    href: "page/company-detail.html?id=" + obj.data.id + "&type=" + "3",
                    title: "编辑企业详情",
                  });
              }
            }
          });
        }

        else if (obj.event === 'delete') {
          //调后台删除（修改）接口
              layer.confirm('真的删除行么', function (index) {
               let id= obj.data.id;
                $.ajax({
                  url: publicurl + 'pro/delPro',
                  type: 'GET',
                  data: {
                    id
                  },
                  dataType: 'json',
                  success: function(res) {
                    if (res.status == 1) {
                      layer.alert(res.msg + '<br>' + res.obj, {
                        icon: 2,
                        title: "提示"
                      },function(index) {
                        if(res.obj=='未登录'){
                          location.href = 'login-1.html'
                        }else{
                          layer.close(index);
                        }

                      });
                    }else {
                      console.log("删除成功")
                      setTimeout(() => {
                        window.location.reload()
                      }, 100)
                      obj.del();
                      layer.close(index);
                    }

                  },
                  error: function(err) {
                    console.log(err)
                  }
                });


              });
            }
      });


    //新增
      $("#add").click(function(){
        $.ajax({
          url:publicurl + 'pro/checkUser',
          type:"GET",
          dataType: 'json',
          async:false,
          success: function(res) {
            if (res.status == 1) {
              layer.alert(res.msg + '<br>' + res.obj, {
                icon: 2,
                title: "提示"
              }, function (index) {
                if(res.obj=='未登录'){
                  location.href = 'login-1.html'
                }else{
                  layer.close(index);
                }

              });
            }else{
              miniTab.openNewTabByIframe({
                href: "page/company-detail.html?type=" + "2",
                title: "新增企业详情",
              });
              //新增
              console.log("新增")
            }
          }
        });


        });
      //刷新
      $(".class1").hover(function (e) {
        // console.log(window.location.href)
        // var router = layui.router();
        //console.log(router);
        //$("#refreshs").css("padding","0 0 100px 0");
        $("#refreshs").height($(window).height()-40)
        let TBaoIDa = localStorage.getItem("TBaoID");
        if(TBaoIDa==1){
          //$("#refreshs").height($(window).height()-30)
          //$("#refreshs").css("padding","0 0 100 0");
          console.log('鼠标移入');
          localStorage.setItem("TBaoID", 0);
          window.location.reload()
        }
      });

    });
  </script>

</body>

</html>